﻿Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data

Public Class sprint

#Region "Properties"

    Private _sprintId As Integer
    Public Property SprintId() As Integer
        Get
            Return _sprintId
        End Get
        Set(ByVal value As Integer)
            _sprintId = value
        End Set
    End Property

    Private _projectID As Integer
    Public Property ProjectID() As Integer
        Get
            Return _projectID
        End Get
        Set(ByVal value As Integer)
            _projectID = value
        End Set
    End Property

    Private _userID As String
    Public Property UserID() As String
        Get
            Return _userID
        End Get
        Set(ByVal value As String)
            _userID = value
        End Set
    End Property

    Private _featureID As Integer
    Public Property FeatureID() As Integer
        Get
            Return _featureID
        End Get
        Set(ByVal value As Integer)
            _featureID = value
        End Set
    End Property

    Private _startDate As String
    Public Property StartDate() As String
        Get
            Return _startDate
        End Get
        Set(ByVal value As String)
            _startDate = value
        End Set
    End Property


    Private _endDate As String
    Public Property EndDate() As String
        Get
            Return _endDate
        End Get
        Set(ByVal value As String)
            _endDate = value
        End Set
    End Property

    Private _projectOwner As String
    Public Property ProjectOwner() As String
        Get
            Return _projectOwner
        End Get
        Set(ByVal value As String)
            _projectOwner = value
        End Set
    End Property

    Private _scrumMaster As String
    Public Property ScrumMaster() As String
        Get
            Return _scrumMaster
        End Get
        Set(ByVal value As String)
            _scrumMaster = value
        End Set
    End Property

    Private _sprintFeatures As DataSet
    Public Property SprintFeatures() As DataSet
        Get
            Return _sprintFeatures
        End Get
        Set(ByVal value As DataSet)
            _sprintFeatures = value
        End Set
    End Property

    Private _featureHours As Integer
    Public Property FeatureHours() As Integer
        Get
            Return _featureHours
        End Get
        Set(ByVal value As Integer)
            _featureHours = value
        End Set
    End Property

    Private _featureTaskCount As Integer
    Public Property FeatureTaskCount() As Integer
        Get
            Return _featureTaskCount
        End Get
        Set(ByVal value As Integer)
            _featureTaskCount = value
        End Set
    End Property

    Private _sprintTotalDevHours As Integer
    Public Property SprintTotalDevHours() As Integer
        Get
            Return _sprintTotalDevHours
        End Get
        Set(ByVal value As Integer)
            _sprintTotalDevHours = value
        End Set
    End Property

    Private _priorSumOfFeatHours As Integer
    Public Property PriorSumOfFeatureHours() As Integer
        Get
            Return _priorSumOfFeatHours
        End Get
        Set(ByVal value As Integer)
            _priorSumOfFeatHours = value
        End Set
    End Property

    Private _postSumOfFeatHours As Integer
    Public Property PostSumOfFeatureHours() As Integer
        Get
            Return _postSumOfFeatHours
        End Get
        Set(ByVal value As Integer)
            _postSumOfFeatHours = value
        End Set
    End Property

#End Region

#Region "Constructors"

    Dim _dal As New ScrumrData

    Sub New()

    End Sub

    Sub New(ByRef iSprintId As Integer)
        Me.GetSprintDetails(iSprintId)
    End Sub

    Public Sub GetSprintDetails(ByRef iSprintId As Integer)
        Me.SprintId = iSprintId
    End Sub

    Public Sub AddSprint(ByVal sStartDate As String, ByVal sEndDate As String)

        Me.StartDate = sStartDate
        Me.EndDate = sEndDate


        Try
            Me.SprintId = _dal.SaveSprint(Me.StartDate, Me.EndDate)
        Catch ex As Exception
            Throw New Exception("Business layer error: " & ex.Message)
        End Try

    End Sub

    Public Sub FillProjectPOandSM(ByVal iProjectID As Integer)

        Me.ProjectID = iProjectID

        Try
            Me.ProjectOwner = _dal.FillProjectOwnerName(Me.ProjectID)
            Me.ScrumMaster = _dal.FillScrumMasterName(Me.ProjectID)
        Catch ex As Exception
            Throw New Exception("Business layer error: " & ex.Message)
        End Try

    End Sub

    Public Sub FillFeatureHoursSum(ByVal iFeatureID As Integer)

        Me.FeatureID = iFeatureID

        Try
            Me.FeatureHours = _dal.SumOfFeatureHours(Me.FeatureID)
        Catch ex As Exception
            Throw New Exception("Business layer error: " & ex.Message)
        End Try

    End Sub

    Public Sub FillDevHoursTotal(ByVal iCount As Integer, ByVal sStartDate As String, ByVal sEndDate As String)

        Me.StartDate = sStartDate
        Me.EndDate = sEndDate

        Try
            Me.SprintTotalDevHours = _dal.DevHoursForSprint(iCount, Me.StartDate, Me.EndDate)
        Catch ex As Exception
            Throw New Exception("Business layer error: " & ex.Message)
        End Try

    End Sub

    Public Sub FillFeatureSubtaskCount(ByVal iFeatureID As Integer)

        Me.FeatureID = iFeatureID

        Try
            Me.FeatureTaskCount = _dal.CountOfFeatureTasks(Me.FeatureID)
        Catch ex As Exception
            Throw New Exception("Business layer error: " & ex.Message)
        End Try

    End Sub

    Public Sub AddDevTeamToSprint(ByVal lbDevTeam As ListBox, ByVal iSprintID As Integer)

        For Each _item As ListItem In lbDevTeam.Items
            If _item.Selected = "True" Then
                _dal.AddDevTeamMemberToSprint(_item.Value, iSprintID)
            End If
        Next _item

    End Sub

    Public Sub FillDevTeamBullet(ByVal blDevTeam As BulletedList, ByVal lbDevTeam As ListBox)

        blDevTeam.Items.Clear()

        For Each _item As ListItem In lbDevTeam.Items
            If _item.Selected = "True" Then
                blDevTeam.Items.Add(_item.Text)
            End If
        Next _item

    End Sub

    Public Sub AddEstHoursForSprint(ByVal iFeatureID As Integer, ByVal iPriorSumOfFeatHours As String)

        Me.FeatureID = iFeatureID

        Try
            Me.FeatureHours = _dal.SumOfFeatureHours(Me.FeatureID)
            Me.PriorSumOfFeatureHours = iPriorSumOfFeatHours
            Me.PostSumOfFeatureHours = Me.PriorSumOfFeatureHours + Me.FeatureHours

        Catch ex As Exception
            Throw New Exception("Business layer error: " & ex.Message)
        End Try

    End Sub

    Public Sub RemoveEstHoursForSprint(ByVal iFeatureID As Integer, ByVal iPriorSumOfFeatHours As String)

        Me.FeatureID = iFeatureID

        Try
            Me.FeatureHours = _dal.SumOfFeatureHours(Me.FeatureID)
            Me.PriorSumOfFeatureHours = iPriorSumOfFeatHours
            Me.PostSumOfFeatureHours = Me.PriorSumOfFeatureHours - Me.FeatureHours

        Catch ex As Exception
            Throw New Exception("Business layer error: " & ex.Message)
        End Try

    End Sub

    Public Sub AddFeaturesToBullet(ByVal lbFeaturesInSprint As ListBox, ByVal blFeaturesInSprint As BulletedList)

        blFeaturesInSprint.Items.Clear()

        For Each _item As ListItem In lbFeaturesInSprint.Items
            blFeaturesInSprint.Items.Add(_item.Text)
        Next _item


    End Sub

    Public Sub AddFeaturesToSprint(ByVal lbFeaturesInSprint As ListBox, ByVal iSprintID As Integer)

        For Each _item As ListItem In lbFeaturesInSprint.Items
            _dal.AddFeatureToSprint(_item.Value, iSprintID)
        Next _item
    End Sub


#End Region
End Class
